/*
⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠟⠛⠉⠙⠿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣿⣿⠿⠋ ⢦⣀⡈⢻⣿⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣿⣇ ⠈⣷⡄⠙⠛⢿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣿⣿⣷⣦⣄ ⢀⣤⣤⣾⣿⠧ ⠈⢿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠿⠃ ⠉⠉ ⢀⣀⣠⣾⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣿⣿⠁ ⢀⣾⣿⣿⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣿⣿ ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣿⠇ ⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⠟⠋ ⠸⣿⣿⣿⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⠇ ⡀ ⠹⣿⣿⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⠋⢀⣾⣿⠇ ⢈⠻⣿⣿⣿⣿⣿⣿⣿
⣿⣿⣿⡇ ⠸⣿⣿ ⠈⢦⠈⢿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣷⣾⣿⠃ ⣸⡆ ⢣⡀⠻⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⡟ ⢀⣿⣿⡀ ⢀⣵⡀⠙⣻⣿⣿
⣿⣿⣿⣿⣿⣿⠁ ⢸⣿⣿⣧ ⠈⢻⣿⣾⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣤ ⢀⣀⣼⣿⣿⣿⡄ ⢴⣾⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⡏ ⣿⣿⣿⣿⣿⣿⣿⣿⣇ ⠈⢿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⠇ ⢠⣿⣿⣿⣿⣿⣿⣿⣿⣿⡄ ⠘⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿ ⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡄ ⢻⣿⣿⣿⣿
⣿⣿⣿⣿⣿⡏ ⣼⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡄⠈⣿⣿⣿⣿
⣿⣿⣿⣿⡿⠁⢠⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡄⠘⣿⣿⣿
⣿⡿⠛⠉ ⠈⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇ ⠈⠻⣿
⣿⣷⣶⣶⣶⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣤⣤⣤⣼
*/
#include<bits/stdc++.h>
#define _CRT_SECURE_NO_WARNINGS
#define ll long long
#define dl double
#define OstorYaRab ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define sorts sort(s.begin(),s.end());
#define sorta sort(arr,arr+n);
#define sortv sort(v.begin(),v.end());
#define all(v) v.begin(),v.end();
#define all(s) s.begin(),s.end();
#define loop0 for(int i = 0 ; i < n ; i++)
#define loop1 for(int i = 1 ; i<= n ; i++)
#define endl "\n"
const dl pi = 3.141592653589793;
const ll INF = (int)1e9;
const ll mod = 1000000000 + 7;
using namespace std;
bool prime(ll n)
{
if (n == 1)
return 0;
for (ll i = 2; i <= sqrt(n); i++)
{
if (n % i == 0)
return 0;
}
return 1;
}
void printBin(int n)
{
if (n <= 1)
{
cout << n;
return;
}
printBin(n >> 1);
cout << (n & 1);
}
ll CountBits(ll n)
{
ll cnt = 0;
while (n)
{
n = n >> 1;
cnt++;
}
return cnt;
}
int CountBits1(int n)
{
int cnt = 0;
while (n)
{
cnt++;
n &= (n - 1);
}
return cnt;
}
ll getBit(ll n, ll idx) { return (n >> idx) & 1; }
int SetLastZero1(int n) { return n | (n + 1); }
int SetLastOne0(int n) { return n & (n - 1); }
int SetFirstConsecutiveZeros1(int n) { return n | (n - 1); }
int SetFirstConsecutiveOnes0(int n) { return n & (n + 1); }
ll setBit1(ll n, ll idx) { return n | (1ll << idx); }
ll setBit0(ll n, ll idx) { return n & ~(1ll << idx); }
int flipBit(int n, int idx) { return n ^ (1 << idx); }
int lastBitValue1(int n) { return n & ~(n - 1); }
int lastBitValue(int n) { return n - (n & (n - 1)); }
int main()
{
OstorYaRab;
//freopen("equal.in", "r", stdin);
//("output.txt", "w", stdout);
ll t = 1;
cin >> t;
while (t--) {
ll n; cin >> n;
vector<ll>arr(n);
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
ll ans = 0, sum = 0;
for (int i = n - 1; i >= 0; i--) {
sum += arr[i];
if (sum > 0)ans += sum;
// 2 11
//13
}
if (sum < 0)ans += sum;
cout << ans << endl;
}
}
74. Search a 2D Matrix | 71. Simplify Path |
62. Unique Paths | 50. Pow(x, n) |
43. Multiply Strings | 34. Find First and Last Position of Element in Sorted Array |
33. Search in Rotated Sorted Array | 17. Letter Combinations of a Phone Number |
5. Longest Palindromic Substring | 3. Longest Substring Without Repeating Characters |
1312. Minimum Insertion Steps to Make a String Palindrome | 1092. Shortest Common Supersequence |
1044. Longest Duplicate Substring | 1032. Stream of Characters |
987. Vertical Order Traversal of a Binary Tree | 952. Largest Component Size by Common Factor |
212. Word Search II | 174. Dungeon Game |
127. Word Ladder | 123. Best Time to Buy and Sell Stock III |
85. Maximal Rectangle | 84. Largest Rectangle in Histogram |
60. Permutation Sequence | 42. Trapping Rain Water |
32. Longest Valid Parentheses | Cutting a material |
Bubble Sort | Number of triangles |
AND path in a binary tree | Factorial equations |